<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>维护报告</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../../../css/mui.min.css">
		<link rel="stylesheet" href="../../../css/global.css">
		<link rel="stylesheet" href="../../../css/style.css">
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">维护报告</h1>
		</header>
		<div class="mui-content">
			<div class="details_con">
				<div class="line"></div>
				<!--<div class="my-content-cell" id="xcfwbg" style="display: none;">
					<div class="inline-block">
						<em>现场服务报告</em>
						<span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
					</div>
				</div>-->
				<div class="my-content-cell" id="azysbg" style="display: none">
					<div class="inline-block" id="anys">
						<em>安装验收报告</em>
						<span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
					</div>
				</div>
				<div class="my-content-cell" id="azzlbg" style="display: none">
					<div class="inline-block">
						<em>安装质量报告</em>
						<span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
					</div>
				</div>
				<!--<div class="my-content-cell" id="dhjjbg" >
					<div class="inline-block" id="pjcgqd">
						<em>电话解决报告</em>
						<span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
					</div>
				</div>-->
				<div class="my-content-cell" id="qzysbgfj" style="display: none">
					<div class="inline-block" id="signReportFileBtn">
						<em>签字验收报告附件</em>
						<span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
					</div>
				</div>
				<div class="my-content-cell" id="gzbgfj">
					<div class="inline-block" id="workReportFileBtn">
						<em>工作报告附件</em>
						<span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
					</div>
				</div>
				<div class="my-content-cell" id="khxcqrd" style="display: none">
					<div class="inline-block" id="serviceVoucherFileBtn">
						<em>客户现场确认单</em>
						<span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
					</div>
				</div>
			</div>
			<div style="height: 50px;"></div>
		</div>

		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../../js/mui.min.js"></script>
		<script src="../../../js/utils/h.js"></script>
		<script src="../../../js/constant.js"></script>
		<script src="../../../js/common.js"></script>
		<script src="../../../js/utils/base64.js"></script>
		<script src="../../../js/utils/md5.js"></script>
		<script src="../../../js/utils/sortMap.js"></script>
		<script src="../../../js/utils/http.js"></script>
		<script src="../../../js/app.js"></script>
		<!-- 基础js end -->

		<script type="text/javascript" charset="utf-8">
			var serviceNo
			var serviceType
			var subServiceType
			
			var planId
			var planState
			var noticeId
			var orderReceivedDate
			var isWarranty
			var problem
			(function($, doc) {
				$.init();
			
				$.plusReady(function() {
					var self = plus.webview.currentWebview();
					serviceNo = self.serviceNo; 
					serviceType = self.serviceType;
					subServiceType = self.subServiceType;
					//电话解决报告需要参数
					planId = self.planId; 
					planState = self.planState;
					noticeId = self.noticeId; 
					orderReceivedDate = self.orderReceivedDate; 
					isWarranty = self.isWarranty; 
					problem = self.problem;
					// h('#xcfwbg').hide()
					getServiceFileHandle();
					if (serviceType == "安装"){
						h('#azysbg').show();
						h('#azzlbg').show();
						h('#qzysbgfj').show();
						h('#khxcqrd').show();
					}

					//查看报告
					h('#ckbg').tap(function() {
						app.jumpTo('/view/service/report/work/customerSignList.html','view/service/report/work/customerSignList.html',
						{
							ServiceNoticeId:noticeId,
							serviceNo:serviceNo,
							planId:planId,
							serviceType:serviceType
						})
					})
					

					
					
					h('#xcfwbg').tap(function() {
						app.showWaiting()
						ajaxGet(BASE_URL + 'cc/notice/getServiceNoticeDetailsAndReportCount', {
							serviceNo: serviceNo,
							serviceNoticeId: noticeId,
							planId: planId,
							enginnerId: app.getUser().enginnerId
						}, function(data) {
							app.closeWaiting()
							if (data.code === 200) {
								
								var reportInfoFinishs = data.data.reportInfoFinishs;
								if (reportInfoFinishs && reportInfoFinishs.length > 0) {
									for (var i = 0; i < reportInfoFinishs.length ; i ++) {
										if(reportInfoFinishs[i].syncFlag == '1') {
											app.toast("已存在现场服务报告");
											return;
										}
									}
								}
								
								var serviceLogs = data.data.serviceLogs;
								if (serviceLogs && serviceLogs.length == 0) {
									app.toast("您已填完现场服务报告，请查看报告");
									return;
								}

								var city = data.data.serviceNotice.city
								var prov = data.data.serviceNotice.province
								var serviceInstrument = data.data.serviceInstrument || {}
								var mdsign = serviceInstrument.mdsign
								var diviBu = serviceInstrument.diviBu
								var divi = ""
								var bu = ""
								if (diviBu && diviBu.indexOf("-") != -1) {
									var diviBus = diviBu.split("-");
									if (diviBus && diviBus.length > 1) {
										divi = diviBus[0]
										bu = diviBus[1]
									}
								}
								
								//先判断是否有服务报告
								app.jumpTo("/view/service/report/fieldservice/report.html",
									"view/service/report/fieldservice/report.html", {
										serviceNo: serviceNo,
										reportId: "",
										planId: planId,
										noticeId: noticeId,
										isWarranty: isWarranty,
										serviceType: serviceType,
										subServiceType: subServiceType,
										divi: divi,
										bu: bu,
										city: city,
										prov: prov,
										problem: problem,
										mdsign: mdsign,
										submitStatus: "0"
									})
								
							} else {
								app.toast(data.msg)
							}
						}, function(errorMsg){
							app.closeWaiting()
							app.toast(errorMsg)
						});
						
						
					})
					
					// 签字验收报告附件
					h('#signReportFileBtn').tap(function() {
						app.jumpTo("../picture/reportPicAdd.html", "/view/service/picture/reportPicAdd.html",
						{
							"serviceNo": serviceNo,
							"helpId": 2
						});
					})
					
					// 工作报告附件
					h('#workReportFileBtn').tap(function() {
						app.jumpTo("../picture/reportPicAdd.html", "/view/service/picture/reportPicAdd.html",
						{
							"serviceNo": serviceNo,
							"helpId": 1
						});
					})
					
					// 客户现场确认单
					h('#serviceVoucherFileBtn').tap(function() {
						app.jumpTo("../picture/reportPicAdd.html", "/view/service/picture/reportPicAdd.html",
						{
							"serviceNo": serviceNo,
							"helpId": 3
						});
					})
					
					// 安装验收报告
					h('#anys').tap(function () {
						app.showWaiting()
						ajaxGet(BASE_URL + 'cc/notice/getServiceNoticeDetailsAndReportCount', {
							serviceNo: serviceNo,
							serviceNoticeId: noticeId,
							planId: planId,
							enginnerId: app.getUser().enginnerId
						}, function(data) {
							app.closeWaiting()
							if (data.code === 200) {
								console.debug(data)
								console.log(JSON.stringify(data))
								
								var reportFinishFlag = false;
								var reportInfoFinishs = data.data.reportInfoFinishs;
								if (reportInfoFinishs && reportInfoFinishs.length > 0) {
									for (var i = 0; i < reportInfoFinishs.length ; i ++) {
										if(reportInfoFinishs[i].syncFlag == '1') {
											reportFinishFlag = true;
											break;
										}
									}
								}
								
								if (reportFinishFlag) {
									
									var acceptanceCount = data.data.acceptanceCount;
									if (acceptanceCount > 0) {
										app.toast('已存在安装验收报告')
										return;
									}
									
									var reportInfo = reportInfoFinishs[0].reportInfo;
									
									var installStartTime = null;
									var installEndTime = null;
									var warrantyStartTime = null;
									var warrantyEndTime = null;
									var computerMfr = null;
									var modelNumber = null;
									var serviceNumber = null;
									var software = null;
									var optionSoftware = null;
									var syssoft = null;
									
									if (reportInfo) {
										installStartTime = reportInfo.startWorkingTime
										installEndTime = reportInfo.endWorkingTime
									}
									
									var serviceInstrument = data.data.serviceInstrument;
									if (serviceInstrument) {
										warrantyStartTime = serviceInstrument.guaranteeStartTime
										warrantyEndTime = serviceInstrument.guaranteeEndTime
									}
									
									var serviceNotice = data.data.serviceNotice;
									if (serviceNotice) {
										computerMfr = serviceNotice.computerMfr;
										modelNumber = serviceNotice.modelNumber;
										serviceNumber = serviceNotice.serviceNumber;
										software = serviceNotice.software;
										optionSoftware = serviceNotice.optionSoftware;
										syssoft = serviceNotice.systemSoftware;
									}

									
									app.jumpTo("/view/service/report/acceptance/add.html",
									"view/service/report/acceptance/add.html",
									{
										serviceNo: serviceNo,
										planId: planId,
										noticeId: noticeId,
										installStartTime: installStartTime,
										installEndTime: installEndTime,
										warrantyStartTime: warrantyStartTime,
										warrantyEndTime: warrantyEndTime,
										computerMfr: computerMfr,
										modelNumber: modelNumber,
										serviceNumber: serviceNumber,
										software: software,
										optionSoftware: optionSoftware,
										syssoft: syssoft
									})
									
								} else {
									app.toast("服务状态为未完成，请先填写服务状态为已完成的服务报告。")
								}
							} else {
								app.toast(data.msg)
							}
						}, function(errorMsg){
							app.closeWaiting()
							app.toast(errorMsg)
						});
					});
					
					// 安装质量报告
					h('#azzlbg').tap(function() {
						app.showWaiting()
						ajaxGet(BASE_URL + 'cc/notice/getServiceNoticeDetailsAndReportCount', {
							serviceNo: serviceNo,
							serviceNoticeId: noticeId,
							planId: planId,
							enginnerId: app.getUser().enginnerId
						}, function(data) {
							app.closeWaiting()
							if (data.code === 200) {
								console.log(JSON.stringify(data))
								
								var reportFinishFlag = false;
								var reportInfoFinishs = data.data.reportInfoFinishs;
								if (reportInfoFinishs && reportInfoFinishs.length > 0) {
									for (var i = 0; i < reportInfoFinishs.length ; i ++) {
										if(reportInfoFinishs[i].syncFlag == '1') {
											reportFinishFlag = true;
											break;
										}
									}
								}
								
								if (reportFinishFlag) {
									
									var installationquality = data.data.installationquality;
									if (installationquality > 0) {
										app.toast('已存在安装质量报告')
										return;
									}
									
									app.jumpTo("/view/service/report/installationquality/add.html", "view/service/report/installationquality/add.html", {
										serviceNo: serviceNo,
										planId: planId,
										ServiceNoticeId: noticeId,
										iqrId: ""
									})
									
								} else {
									app.toast("服务状态为未完成，请先填写服务状态为已完成的服务报告。")
								}
							} else {
								app.toast(data.msg)
							}
						}, function(errorMsg){
							app.closeWaiting()
							app.toast(errorMsg)
						});
					})
					
					//关闭页面
					h('#gbym').tap(function() {
						mui.back()
					})
				});
			}(mui, document));
			
			//获取报告附件状态
			function getServiceFileHandle(){
				app.showWaiting();
				ajaxGet(BASE_URL + 'cc/service/annex/getServiceFileHandle', {
					serviceNo: serviceNo,
				}, function(data) {
					if (data && data.code == 200){
						var fileData = JSON.parse(data.data).record[0]
						if(fileData.EngCus){
							h('#khxcqrd em').html('客户现场确认单（已上传）')
						}
						if(fileData.EngineerAffix){
							h('#qzysbgfj em').html('签字验收报告附件（已上传）')
						}
						if(fileData.EngineerReport){
							h('#gzbgfj em').html('工作报告附件（已上传）')
						}
						app.closeWaiting()
					}else{
						app.closeWaiting()
					}
				},function(errMsg){
					app.closeWaiting()
					app.toast(errorMsg)
				})
			}
			
			function addPictureSuccess() {
				getServiceFileHandle();
			}
		</script>
		<!-- js代码 end -->

	</body>

</html>
